#include "CarControl.h"
#include "Delay.h"
#include "gec_init.h"
#include "gec_gpio.h"
#include "LED.h"


void PWMInit() {

}

//右轮全速后退,左轮差速后退
void PWMCarGoLeftBack(int duty) {
  int i = 200;
  if(duty <0 || duty > 10) {
    duty = 10;
  }
  
  PAout(4) = 1;
  PBout(7) = 0;

  PDout(6) = 1;

  while(i--) {
    PDout(7) = 0;
    Delay_ms(duty);
    PDout(7) = 1;
    Delay_ms(10 - duty);

  }
}

//右轮全速后退,左轮差速后退
void PWMCarGoRightBack(int duty) {
  int i = 200;
  if(duty <0 || duty > 10) {
    duty = 10;
  }
  
	PDout(6) = 1;
	PDout(7) = 0;
	
  PAout(4) = 1;
  

  

  while(i--) {
    PBout(7) = 0;
    Delay_ms(duty);
    PBout(7) = 1;
    Delay_ms(10 - duty);

  }
}

//减慢左边轮速度前进
void PWMCarAdjust(int duty) {
  int i = 200;
  if(duty <0 || duty > 10) {
    duty = 10;
  }
  
	PDout(6) = 0;
	PDout(7) = 1;
	
  PAout(4) = 0;
  

  

  while(i--) {
    PBout(7) = 1;
    Delay_ms(duty);
    PBout(7) = 0;
    Delay_ms(10 - duty);

  }
}

